# encoding    : utf-8 -*-                            
# @author     :
# @file       :   优化.py
# @Time       :   2024/12/5 19:05
# -*-coding: Utf-8 -*-
# @File : SinaPage.py .py
# author:
# Time：2024/3/15
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
# from appium.webdriver.common.appiumby import AppiumBy
from appium.webdriver.common.touch_action import TouchAction
# import pyautogui
import time


class AppPage:
    def __init__(self,driver):
        self.driver = driver
        time.sleep(10)

        def login(self, username, password):
            # 假设登录按钮的ID是'com.sina.weibo:id/login_button'
            self.driver.find_element(MobileBy.ID,
                                     "com.sina.weibo:id/login_button").click()
            time.sleep(5)

            # 输入用户名
            username_field = self.driver.find_element(MobileBy.ID,
                                                      "com.sina.weibo:id/login_username")
            username_field.clear()
            username_field.send_keys(username)
            time.sleep(2)

            # 输入密码
            password_field = self.driver.find_element(MobileBy.ID,
                                                      "com.sina.weibo:id/login_password")
            password_field.clear()
            password_field.send_keys(password)
            time.sleep(2)

            # 点击登录
            self.driver.find_element(MobileBy.ID,
                                     "com.sina.weibo:id/login_submit").click()
            time.sleep(10)



    def click_agreement(self):
        self.driver.find_element(MobileBy.XPATH,'/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.LinearLayout/android.widget.TextView[3]').click()
        time.sleep(10)

    def click_discover(self):
        TouchAction(self.driver).tap(x=721, y=2444).perform()
        time.sleep(10)


    def click_known(self):
        TouchAction(self.driver).tap(x=708, y=1933).perform()
        time.sleep(10)

    def click_search_box(self):
        TouchAction(self.driver).tap(x=733, y=191).perform()
        time.sleep(10)


    def enter_search_box_send(self,keyword):
        ele = self.driver.find_element(MobileBy.ID, "com.sina.weibo:id/tv_search_keyword")

        ele.send_keys(keyword)
        time.sleep(5)

    def perform_search(self):
        self.driver.press_keycode(66)
        time.sleep(10)


    def swipe_page(self):
        for i in range(5):
            TouchAction(self.driver).press(x=774, y=1967).move_to(x=774, y=646).release().perform()
            time.sleep(5)
